define(['dojo/_base/declare', 'dojo/request/xhr', 'dijit/_Widget', 'dijit/_TemplatedMixin',
	'dojo/text!feedEditor/widget/MovieItem.html', 'dojox/html/entities', 'dojo/_base/lang'],
	function(declare, xhr, _Widget, TemplatedMixin, template, entities, lang) {
		return declare('feedEditor.widget.MovieItem', [_Widget, TemplatedMixin], {
			templateString: template,

			_id: null,
			_title: null,
			_titleSpan: null,

			constructor: function(mixin, node, id, title, parent) {
				this._id = id;
				this._title = title;
				this._parent = parent; //TODO use model
			},

			postCreate: function() {
				this.inherited(arguments);
				this._titleSpan.innerHTML = entities.encode(this._title);
			},

			_onRemoveClick: function() {
				xhr('/tt-rss-feed-editor/FeedEditor', {
					method: 'POST',
					data: {
						'type': 'remove',
						'id': this._id
					},
					sync: true
				}).then(lang.hitch(this._parent ,this._parent._getMovies));
			}

		});
	});